var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: null,
    statis: null
  },
  // 订单跳转列表
  dingdan: function () {
    wx.navigateTo({
      url: '../schedule/schedule'
    })
  },

  // 分享码
  fenxiang: function () {
    wx.navigateTo({
      url: '/pages/all/share/share?code=' + app.globalData.userInfo.mobile
    })
  },

  // 团队跳转列表
  tuandui: function () {
    wx.navigateTo({
      url: '/pages/all/team/team?code=' + app.globalData.userInfo.pa
    })
  },

  //业务接单列表
  yewu: function () {
    wx.navigateTo({
      url: '../business/business'
    })
  },
  //我的业绩列表
  yeji: function () {
    wx.navigateTo({
      url: '../performance/performance',
    })
  },
  
  //我的提现
  tixian: function () {
    wx.navigateTo({
      url: '/pages/withdrawal/deposit/deposit',
    })
  },

  // 权限跳转列表
  shengji: function () {
    wx.navigateTo({
      url: '../shengji/shengji'
    })
  },
  // 联系我们跳转列表
  lianxi: function () {
    wx.navigateTo({
      url: '../contact/contact'
    })
  },
  // 商学院跳转列表
  xueyuan: function () {
    wx.navigateTo({
      url: '../college/college'
    })
  },

  getUserInfo: function (e) {
    let that = this

    let input = {}
    
    input.nickName = e.detail.userInfo.nickName
    input.avatarUrl = e.detail.userInfo.avatarUrl
    if(app.globalData.userInfo != null && app.globalData.userInfo.openId != null)
      input.openId = app.globalData.userInfo.openId

    wx.showLoading({
      title: '通讯中...',
    });
    wx.request({
      url: app.globalData.serviceUrl + "/wcSysUser/updateByOpenId",
      method: "post",
      data: input,
      success: function (resp) {
        wx.hideLoading();
        if (resp.data.success) {
          app.globalData.userInfo = resp.data.data;

          that.setData({
            userInfo: resp.data.data,
          });

          wx.showToast({
            title: "更新成功",
            icon: 'none',
          });

        } else {
          wx.showToast({
            title: "请先注册后再更新头像",
            icon: 'none',
          });
        }
      },
      fail: function (error) {
        wx.hideLoading();
        wx.showToast({
          title: "通讯异常: " + JSON.stringify(error),
          icon: 'none',
        });
      }
    });


  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userInfo: app.globalData.userInfo
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let that = this

    if (that.data.userInfo != null && that.data.userInfo.id != null) {
      wx.showLoading({
        title: '通讯中...',
      });
      wx.request({
        url: app.globalData.serviceUrl + "/wcSysUser/statistics",
        method: "get",
        data: {
          userId: that.data.userInfo.id
        },
        success: function (resp) {
          wx.hideLoading();
          if (resp.data.success) {
            that.setData({
              statis: resp.data.data,
            });
          }
        },
        fail: function (error) {
          wx.hideLoading();
          wx.showToast({
            title: "通讯异常: " + JSON.stringify(error),
            icon: 'none',
          });
        }
      });
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})